package com.niiwoo.civet.user.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.niiwoo.activity.stage.constant.ActivityRabbitConstant;
import com.niiwoo.civet.account.constant.MQConstant;
import com.niiwoo.civet.user.constants.UserRabbitConstant;

@Configuration
public class RabbitConfiguration {

    @Bean
    public Exchange ucIdentityExchange(RabbitAdmin admin) {
        Exchange exchange = new DirectExchange(MQConstant.UC_IDENTITY_EXCHANGE, true, true);
        admin.declareExchange(exchange);
        return exchange;
    }

    @Bean
    public Queue ucIdentityDataQueue(RabbitAdmin admin) {
        Queue queue = new Queue(MQConstant.UC_IDENTITY_DATA_QUEUE, true);
        admin.declareQueue(queue);
        return queue;
    }

    @Bean
    public Binding ucIdentityBinding(RabbitAdmin admin) {
        Binding binding = BindingBuilder.bind(ucIdentityDataQueue(admin)).to(ucIdentityExchange(admin)).with(MQConstant.UC_IDENTITY_DATA_ROUTING).noargs();
        admin.declareBinding(binding);
        return binding;
    }

    @Bean
    public Exchange dataBackflowRetryExchange(RabbitAdmin admin) {
        Exchange exchange = new DirectExchange(UserRabbitConstant.Exchange.DATA_BACKFLOW_RETRY, true, true);
        admin.declareExchange(exchange);
        return exchange;
    }

    @Bean
    public Queue dataBackflowRetryQueue(RabbitAdmin admin) {
        Queue queue = new Queue(UserRabbitConstant.Queue.DATA_BACKFLOW_RETRY, true);
        admin.declareQueue(queue);
        return queue;
    }

    @Bean
    public Binding dataBackflowRetryBinding(RabbitAdmin admin) {
        Binding binding = BindingBuilder.bind(dataBackflowRetryQueue(admin)).to(dataBackflowRetryExchange(admin)).with(UserRabbitConstant.RoutingKey.DATA_BACKFLOW_RETRY).noargs();
        admin.declareBinding(binding);
        return binding;
    }

//    @Bean
//    public Exchange tagRealNameExchange(RabbitAdmin admin) {
//        Exchange exchange = new DirectExchange(BizEventRabbitConstant.Exchange.BIZ_EVENT_USER_REAL_NAME_FANOUT_EXCHANGE, true, true);
//        admin.declareExchange(exchange);
//        return exchange;
//    }

//
//    @Bean
//    public Queue tagRealNameQueue(RabbitAdmin admin) {
//        Queue queue = new Queue(BizEventRabbitConstant.Queue.BIZ_EVENT_USER_REAL_NAME_QUEUE, true);
//        admin.declareQueue(queue);
//        return queue;
//    }
//
//    @Bean
//    public Binding tagRealNameBinding(RabbitAdmin admin) {
//        Binding binding = BindingBuilder.bind(tagRealNameQueue(admin)).to(tagRealNameExchange(admin)).with(BizEventRabbitConstant.Key.BIZ_EVENT_USER_REAL_NAME_KEY).noargs();
//        admin.declareBinding(binding);
//        return binding;
//    }
    
    /**********************  添加用 户引流渠道信息（用户注册） ********************/
    @Bean
    public Exchange addDraingeChannelUseExchange() {
        return new DirectExchange(ActivityRabbitConstant.Exchange.ADD_DRAINGE_CHANNEL_USE_EXCHANGE, true, true);
    }

    @Bean
    public Queue addDraingeChannelUseQueue() {
        return new Queue(ActivityRabbitConstant.Queue.ADD_DRAINGE_CHANNEL_USE_QUEUE, true);
    }

    @Bean
    public Binding addDraingeChannelUseBinding() {
        return BindingBuilder.bind(addDraingeChannelUseQueue()).to(addDraingeChannelUseExchange()).with(ActivityRabbitConstant.Key.ADD_DRAINGE_CHANNEL_USE_KEY).noargs();
    } 
    
    /**********************  编辑用户引流渠道信息（用户登录） ********************/
    @Bean
    public Queue editDraingeChannelUseQueue() {
        return new Queue(ActivityRabbitConstant.Queue.EDIT_DRAINGE_CHANNEL_USE_QUEUE, true);
    }

    @Bean
    public Binding editDraingeChannelUseBinding() {
        return BindingBuilder.bind(editDraingeChannelUseQueue()).to(addDraingeChannelUseExchange()).with(ActivityRabbitConstant.Key.EDIT_DRAINGE_CHANNEL_USE_KEY).noargs();
    } 
}
